function GetNextCity(provider, callback, errback)
{
    $.ajax({
    
        data: "request=NextCityWS&service=GeocoverageWS&version=1.0.0&Providertype="+provider,
        dataType: "xml",
        error: function (XMLHttpRequest, textStatus, errorThrown) 
        {
            errback("GetNextCity http failure");
        },
        success: function(xml)
        {
            if($('city:first',xml).length==1)
                callback($('city:first',xml).attr("guid"), $('city:first',xml).attr("Y"), $('city:first',xml).attr("X"));
            else
                errback("errback invalid xml");
        }
    });
}

function SendTilesToServer(guid, zoom, typemap, tiles, callback, errback)
{
    if (tiles != null && tiles != "")
    {
        $.ajax({type: "POST",
            data: "request=WriteCityTiles&service=GeoCoverageWS&version=1.0.0&GUID="+guid+"&tilesUrl="+escape(tiles)+"+&ZoomLevel="+zoom+"&MapType="+typemap,
            dataType: "text",
            error: function (XMLHttpRequest, textStatus, errorThrown) 
            {
                errback("WriteCityTiles http failure in SendTilesToServer, gid="+guid+", zoom="+zoom+", tiles="+tiles+", typemap ="+typemap);
            },
            success: function (text)
            {
                if(text!="OK\n")
                     errback("WS Failure in SendTilesToServer, gid="+guid+", zoom="+zoom+", typemap ="+typemap+", tiles="+tiles+": "+text);
                else
                     callback();
           }
        });
    }
    else
        callback();
}

function SendCopyrTilesToServer(guid, zoom, typemap, tiles, callback, errback)
{
    if (tiles != null && tiles != "")
    {
        $.ajax({type: "POST",
            data: "request=WriteCopyrTiles&service=GeoCoverageWS&version=1.0.0&GUID="+guid+"&tilesUrl="+escape(tiles)+"+&ZoomLevel="+zoom+"&MapType="+typemap,
            dataType: "text",
            error: function (XMLHttpRequest, textStatus, errorThrown) 
            {
                errback("WriteCopyrTiles http failure in SendTilesToServer, gid="+guid+", zoom="+zoom+", tiles="+tiles+", typemap ="+typemap);
            },
            success: function (text)
            {
                if(text!="OK\n")
                     errback("WS Failure in SendTilesToServer, gid="+guid+", zoom="+zoom+", typemap ="+typemap+", tiles="+tiles+": "+text);
                else
                     callback();
           }
        });
    }
    else
        callback();
}


function SendResultToServer(guid, zoom, typemap, covcode, covvalue, endprocess, callback, errback)
{
    if (covvalue != null && covvalue != "")
    {
        $.ajax({
            data: "request=WriteResDatabase&service=GeoCoverageWS&version=1.0.0&GID="+guid+"&CovCode="+covcode+"&CovValue="+escape(covvalue)+"&ZoomLevel="+zoom+"&MapType="+typemap+"&EndProcess="+ endprocess,
            dataType: "text",
            error: function (XMLHttpRequest, textStatus, errorThrown) 
            {
                errback("WriteResDatabase http failure in SendResultToServer, gid="+guid+", zoom="+zoom+", covcode="+covcode+", covvalue="+covvalue+", MapType="+typemap+", endprocess="+endprocess);
            },
            success: function (text)
            {
                if(text!="OK\n")
                    errback("WS Failure in SendResultToServer, gid="+guid+", zoom="+zoom+", covcode="+covcode+", covvalue="+covvalue+", MapType="+typemap+", endprocess="+endprocess+": "+text);
                else
                    callback();
            }
        });
    }
    else
        callback();
}



function LogMsg(msg)
{
    $("#ContentArea").prepend(msg+"<br/>");
}

$(document).ready(function()
{
    $("body").append("<div id='ContentArea' style='font-family: tahoma,arial,sans-serif; font-size: 10px'></div>");
});